package a_math;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;

/**
 * @author Cheng-02
 * @version V1.0
 * @Package a_math
 * @date 2024/4/6 16:02
 */
public class test11 {
    public static void main(String[] args) {
        format();
        parse();


    }

    private static void parse() {
      DateTimeFormatter formatter =   DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
      String time="2024-04-06 16:02:02";
     TemporalAccessor temporalAccessor = formatter.parse(time);
        LocalDateTime localDateTime =  LocalDateTime.from(temporalAccessor);
        System.out.println(localDateTime);
    }

    private static void format() {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime now = LocalDateTime.now();
//        String format(TemporalAccessor temporal)  将日期对象按照指定规则转换成String
//        TemporalAccessor：接口，
//        Temporal实现类：LocalDateTime ， LocalTime
        String format1 = now.format(formatter);
        System.out.println(format1);
//        TemporalAccessor parse(CharSequence text) 将符合规则的字符串转换成日期对象
    }
}
